import React, { Component } from 'react'
import { Form, Input, Button } from 'antd'
import { userLogin, getUserInfo } from '../api/user'
import './Login.css'

export default class Login extends Component {
    onFinish = (info) => {
        userLogin(info).then(res => {
            console.log(res.data)
            sessionStorage.setItem('token', res.data.token)
            // 获取用户信息
            getUserInfo().then(res => {
                console.log(res)
            })
        })
    };

    onFinishFailed = (errorInfo) => {
        console.log('Failed:', errorInfo);
    };
    render() {
        return (
            <div className="h100 login">
                <div className="warp">
                    <Form
                        name="basic"
                        labelCol={{ span: 8 }}
                        wrapperCol={{ span: 16 }}
                        onFinish={ this.onFinish }
                        onFinishFailed={ this.onFinishFailed }
                        autoComplete="off"
                    >
                        <Form.Item
                            label="账号"
                            name="user_name"
                            rules={[{ required: true, message: '请输入账号', min: 6 }]}
                        >
                            <Input />
                        </Form.Item>

                        <Form.Item
                            label="密码"
                            name="user_pwd"
                            rules={[{ required: true, message: '请输入密码' }]}
                        >
                            <Input.Password />
                        </Form.Item>

                        <Form.Item wrapperCol={{ offset: 8, span: 16 }}>
                            <Button type="primary" htmlType="submit">
                                登录
                            </Button>
                        </Form.Item>
                    </Form>
                </div>
            </div>
        )
    }
}
